package com.sc.nft.dao;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sc.nft.entity.vo.ecology.AdminExchangeCastUpperLimitConfVO;
import com.sc.nft.entity.vo.ecology.ExchangeCastUpperLimitConfVO;
import lombok.extern.slf4j.Slf4j;
import com.sc.nft.entity.EcologyCastExchangeConf;
import com.sc.nft.mapper.EcologyCastExchangeConfMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 生态-铸造上限兑换配置表(sc_ecology_cast_exchange_conf)数据DAO
 *
 * @author Sun
 * @description 由 Mybatisplus Code Generator 创建
 * @since 2024-06-07 09:03:55
 */
@Slf4j
@Repository
public class EcologyCastExchangeConfDao extends ServiceImpl<EcologyCastExchangeConfMapper, EcologyCastExchangeConf> {

    public boolean getIsExistByEcologyCastIdAndEquityPropsId(Long ecologyCastId, Long equityPropsId) {
        LambdaQueryWrapper<EcologyCastExchangeConf> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(EcologyCastExchangeConf::getEcologyCastId, ecologyCastId);
        wrapper.eq(EcologyCastExchangeConf::getEquityPropsId, equityPropsId);
        return count(wrapper) > 0;
    }

    public boolean getIsExistByEcologyCastId(Long ecologyCastId) {
        LambdaQueryWrapper<EcologyCastExchangeConf> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(EcologyCastExchangeConf::getEcologyCastId, ecologyCastId);
        wrapper.eq(EcologyCastExchangeConf::getStatus, Boolean.TRUE);
        return count(wrapper) > 0;
    }

    public boolean dealExchangeCastUpperLimitById(Long id) {
        return removeById(id);
    }

    public List<AdminExchangeCastUpperLimitConfVO> getExchangeCastUpperLimitConf(Long ecologyCastId) {
        return baseMapper.getExchangeCastUpperLimitConf(ecologyCastId);
    }

    public boolean updateStatusById(Long id, Boolean status) {
        LambdaUpdateWrapper<EcologyCastExchangeConf> wrapper = new LambdaUpdateWrapper<>();
        wrapper.eq(EcologyCastExchangeConf::getId, id);
        wrapper.set(EcologyCastExchangeConf::getStatus, status);
        return update(new EcologyCastExchangeConf(), wrapper);
    }

    /**
     * 获取生态铸造上限兑换配置
     *
     * @param ecologyCastId
     * @return
     */
    public List<ExchangeCastUpperLimitConfVO> getExchangeCastUpperLimitConfList(Long userId, Long ecologyCastId) {
        return baseMapper.getExchangeCastUpperLimitConfList(userId, ecologyCastId);
    }
}